﻿<!--#include file="inc/common.asp" -->
<%
'Blog文章列表显示页面
'
'author: evan zhao
'
  response.AddHeader "Last-Modified", DateToGMT(Now())
  response.Expires = 60
  response.CacheControl = "public"  
  
  
    call openDB
    dim pageSize, pageNo, q_blog_id, q_cat_id, q_start_date, q_end_date, q_user_name, q_title, q_excerpt, q_detail, q_more

    pageSize=100

    pageNo = request("pageno")
    q_blog_id = request("blog_id")
    q_cat_id  = request("cat_id")
    q_start_date  = request("start_date")
    q_end_date  = request("end_date")

    q_user_name = filterHTML(request("q_user_name"))
    q_title = filterHTML(request("q_title"))
    q_excerpt = filterHTML(request("q_excerpt"))
    q_detail = filterHTML(request("q_detail"))
    q_more = filterHTML(request("q_more"))
    
    
    public sub writeItems()
        dim rs, sql

        if pageNo="all" then
            'sql = " select  "
        else
            if isEmpty(pageNo) or pageNo="" then
              pageNo = 1
            end if    
            pageNo = clng(pageNo)
            if pageNo<1  then
                pageNo=1
            end if
            'sql = " select top " & (pageNo * pageSize ) 
        end if
        
        sql = " select a.content_id,a.title,a.user_name,a.user_id,a.end_date ,a.start_date  ,a.insert_time,a.is_secret, b.blog_id,b.blog_title,c.cat_id,c.cat_name from (blog_content a inner join blog b on a.blog_id=b.blog_id) left outer join blog_category c on a.cat_id=c.cat_id  where 1=1 "
        
        if not isEmpty(q_blog_id) and q_blog_id<>"" then
            sql = sql & " and a.blog_id=" & clng(q_blog_id)
        end if

        if isNull(q_cat_id) or q_cat_id="null"  then
            sql = sql & " and a.cat_id is null "
        elseif not isEmpty(q_cat_id) and q_cat_id<>"" then
            sql = sql & " and a.cat_id=" & clng(q_cat_id)
        end if
        
        if not isEmpty(q_start_date) and q_start_date<>"" then
            if len(q_start_date)=4 then '2004
                q_start_date = q_start_date& "-01-01" 
            elseif len(q_start_date)=6 or  len(q_start_date)=7  then '2004-1 2004-01
                q_start_date = q_start_date& "-01" 
            end if    
            sql = sql & " and a.start_date>=#" & q_start_date& "# "
        end if    
        
        if not isEmpty(q_end_date) and q_end_date<>"" then
            if len(q_end_date)=4 then '2004
                q_end_date = q_end_date& "-12-31" 
                sql = sql & " and a.end_date<#" & q_end_date& "#+1 "
            elseif len(q_end_date)=6 or  len(q_end_date)=7  then '2004-1 2004-01
                if clng(mid(q_end_date,6))<12 then
                    q_end_date = left(q_end_date,4)&"-"& (clng(mid(q_end_date,6))+1)& "-01"
                else
                    q_end_date = (clng(left(q_end_date,4))+1)& "-01-01" 
                end if
                sql = sql & " and a.end_date<#" & q_end_date& "# "
            else
                sql = sql & " and a.end_date<#" & q_end_date& "#+1 "
            end if    
        end if    

        if not isEmpty(q_user_name) and q_user_name<>"" then
            sql = sql & " and a.user_name like '%" & q_user_name & "%' "
        end if        
        
        if not isEmpty(q_title) and q_title<>"" then
            sql = sql & " and a.title like '%" & q_title & "%' "
        end if        
        
        if not isEmpty(q_excerpt) and q_excerpt<>"" then
            sql = sql & " and a.excerpt like '%" & q_excerpt & "%' "
        end if        

        if not isEmpty(q_detail) and q_detail<>"" then
            sql = sql & " and a.detail like '%" & q_detail & "%' "
        end if        

        if not isEmpty(q_more) and q_more<>"" then
            sql = sql & " and a.more like '%" & q_more & "%' "
        end if        

        sql = sql & "  order by a.start_date desc ,a.insert_time desc"
        
        'response.write sql
        'response.end
        
        set rs = Server.createObject("ADODB.RecordSet")
        rs.open sql,conn,1,1
        
        dim content_id, title, user_name, user_id, blog_id, blog_title, cat_id, cat_name
        dim end_date ,start_date  ,insert_time, is_secret
        dim start_date_str, end_date_str, insert_time_str
        dim last_date_str
                
        set content_id = rs("content_id")
        set title = rs("title")
        set user_name = rs("user_name")
        set user_id = rs("user_id")
        set blog_id = rs("blog_id")
        set blog_title = rs("blog_title")
        set cat_id = rs("cat_id")
        set cat_name = rs("cat_name")
        set content_id = rs("content_id")
        set end_date = rs("end_date")
        set start_date = rs("start_date")
        set insert_time = rs("insert_time")
        set is_secret = rs("is_secret")

        if not rs.eof then
            dim i, pageCount
            i=0
            pageCount = 0

            rs.pageSize=pageSize
            if pageNo<>"all" then
                rs.absolutePage=pageNo
                pageCount = rs.pageCount
            end if
                

            do while not rs.eof and (pageNo="all" or i<pageSize )
                if not is_secret or user_id=userObj.userId or userRightObj.canReadSecret then
                
                    start_date_str = FORMATDATETIME(start_date, vbShortDate)
                    end_date_str = FORMATDATETIME(end_date, vbShortDate)
                    insert_time_str = FORMATDATETIME(insert_time, vbShortDate)
                    
                    if i mod pageSize=0 then
                    'if last_date_str<>end_date_str or last_date_str<>start_date_str then
                        if i>0 then
                            response.write("</table></p>         " & vbCrLf )
                            assertConnected()
                        end if
                        'response.write("<p><strong>日期</strong>：" )
                        'if start_date_str = end_date_str  then 
                        '    response.write end_date_str  
                        'else                                                                        
                        '    response.write start_date_str &" ~ "& end_date_str 
                        'end if    
    
                        response.write("<table align=center border=0 width=100% >        " & vbCrLf )
                        response.write("    <tr>                                         " & vbCrLf )
                        response.write("      <td  width=6% ><strong>日期</strong></td> " & vbCrLf )
                        response.write("      <td  width=12% ><strong>Blog</strong></td> " & vbCrLf )
                        response.write("      <td  width=12% ><strong>分类</strong></td> " & vbCrLf )
                        response.write("      <td><strong>标题</strong></td>             " & vbCrLf )
                        response.write("      <td  width=12% ><strong>作者</strong></td> " & vbCrLf )
                        response.write("      <td  width=6% ><strong>时间</strong></td> " & vbCrLf )
                        response.write("    </tr>                                        " & vbCrLf )
                    end if
    
                    response.write("  <td nowrap >")
                    if last_date_str<>start_date_str then
                        response.write start_date_str
                    end if
                    response.write("&nbsp;</td>    " & vbCrLf ) 
                    response.write("  <td nowrap><a href='index.asp?blog_id=" & blog_id & "'>" & blog_title & "</a>&nbsp;</td>    " & vbCrLf ) 
                    response.write("  <td nowrap><a href='index.asp?blog_id=" & blog_id & "&cat_id=" & cat_id & "'>" & cat_name & "</a>&nbsp;</td>    " & vbCrLf ) 
                    response.write("  <td><a href='detail.asp?blog_id=" & blog_id & "&content_id=" & content_id & "'>" & title & "</a>&nbsp;</td>    " & vbCrLf ) 
                    response.write("  <td nowrap><a href='user.asp?blog_id=" & blog_id & "&user_id=" & user_id & "'>" & user_name & "</a>&nbsp;</td>    " & vbCrLf ) 
                      
                    response.write("  <td nowrap>")
                    if start_date_str = insert_time_str then 
                        response.write  FORMATDATETIME(insert_time, vbShortTime)
                    else                                                                        
                        'response.write "<span title='"&insert_time_str &" "&  FORMATDATETIME(insert_time, vbShortTime)&"'>补</span>" '                                      
                        response.write insert_time_str &" "&  FORMATDATETIME(insert_time, vbShortTime)
                    end if    
                    response.write("&nbsp;</td>                 " & vbCrLf ) 
                    
                    response.write("</tr>                       " & vbCrLf ) 
                
                    last_date_str=end_date_str                                                                  
                end if    
                i = i+1
                rs.moveNext()
            loop    
            response.write("</table>         " & vbCrLf )
            if pageNo<>"all" and pageCount>0 then
                response.write("<p align= center>" & vbCrLf )
                response.write(getPageLink(pageCount, pageNo, pageSize, i, "list.asp?blog_id="&q_blog_id&"&cat_id="&q_cat_id&"&start_date="&request("start_date")&"&end_date="&request("end_date")&"&q_user_name="&q_user_name&"&q_title="&q_title&"&q_excerpt="&q_excerpt&"&q_detail="&q_detail&"&q_more="&q_more, "pageno"))
                response.write("</p>" & vbCrLf )
            end if    
        else    
            response.write "没有数据"    
        end if

        rs.close()
        set rs = Nothing
    end sub

%>
<HTML>
<HEAD><TITLE><%=hostTitle%></TITLE>
<META http-equiv=Content-Type content="text/html; charset=<%=DEFAULT_CHARSET%>">
<link rel="stylesheet" href="list.css" type="text/css" />
</HEAD>

<body>
<%
call writeItems()
%>                

 

</body>
</HTML>
<!--#include file="inc/end.asp" -->